package com.example;

import com.example.dao.PostDao;
import com.example.domain.Post;
import com.example.utils.MyBatisUtil;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.List;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }


    @Test
    public void test() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        PostDao mapper = sqlSession.getMapper(PostDao.class);
        int page = 2; // 页码从 1 开始
        int pageSize = 10; // 每页的记录数
        int offset = (page - 1) * pageSize; // 计算偏移量
        RowBounds rowBounds = new RowBounds(offset, pageSize);
        List<Post> postsByPage = mapper.getPostsByPage(rowBounds);
        for (Post post: postsByPage) {
            System.out.println(post.getTitle());
        }
    }
}